package org.example.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.example.utils.LogUtils;

import java.util.List;

public class Byte2IntegerDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
         while (in.readableBytes() > 4) {
            int i = in.readInt();
            LogUtils.info("解码出一个整数：" + i);
            // out中每一个元素都会触发后面的channelRead方法
            out.add(i);
         }
    }
}
